$(function(){
  $(".menu").click(function(){
    $('.wap').toggle();
    $(this).toggleClass('on')
  });
})
document.write('<link rel="icon" type="image/x-icon" href="https://suzhou.xfyun.cn/hera/img/favicon-e30f2b208a8989441f93a044956c2c0e.png" />')


var http = 'http://jc.vipsups.com'; //接口请求域名
function ajax(type,url,data,runFun){
  $.ajax({
    type : type,//请求方式
    contentType: "application/x-www-form-urlencoded",//"multipart/form-data",//请求的媒体类型
    url : http+'/'+url,//请求地址
    async : true, 
    data : data,
    headers: {
      'token': localStorage.getItem('token') // 正确的属性名称是 headers
    },
    success : function(res) {
      if(res.code === 1){
        runFun(res.data)
      }else{
        showToast(res.msg);
      }
    },
    complete:function(){
        $('#app').css('opacity',1)
    },
  });
};

function getProductList (data, fun){
  ajax('GET', '/api/product/getProductList', data, fun)
}
function getProductStockApi (data, fun){
  ajax('POST', '/api/product/getProductStock', data, fun)
}
function setOrdersApi (data, fun){
  ajax('POST', '/api/orders/setOrders', data, fun)
}
function ordersListApi (data, fun){
  ajax('GET', '/api/orders/ordersList', data, fun)
}
function ordersDetailApi (data, fun){
  ajax('GET', '/api/orders/ordersDetail', data, fun)
}
function getUserInfoApi (data, fun){
  ajax('GET', '/api/user/getUserInfo', data, fun)
}





localStorage.setItem('token', '	65321aff-1e02-4c77-8371-d0cc6cc838cb')
// 电话号码
function info(){
  const data = {
    tel:'400-823-0180',
    company:'北京智途教育科技有限公司'
  }
  return data
}

//获取参数    
function getId (key) {
    var url = window.location.search;
    var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
    var result = url.substr(1).match(reg);
    return result ? decodeURIComponent(result[2]) : null;
}
function regM(value){
  var reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
  return reg.test(value)
}
// 验证手机号
function rulePhone (rule, value, callback){
  if (!value) {
    return callback(new Error('手机号不能为空'));
  } else {
    var reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
    console.log(reg.test(value));
    if (reg.test(value)) {
      callback();
    } else {
      return callback(new Error('请输入正确的手机号'));
    }
  }
}


function showToast (msg){
  $('#msg').text(msg)
  $('#msg').show();
  
  setTimeout(()=>{
    $('#msg').hide();
    $('#msg').text('')
  },1500)
}